#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/wait.h>
#include<sys/types.h>


int main()
{

  extern char**environ;
  pid_t id=fork();
  if(id==0)
  {
    //child
    printf("我是子进程:%d\n",getpid());
    //execl("/bin/ls","ls","-a","-l",NULL);
    //binchar *const myargv[]={ 
      //"ls",
      //"-a",
      //"-l",
      //"-n",
      //NULL 
    //};
    //execv("/bin/ls",myargv);
    // execlp("ls","ls","-a","-l",NULL);
    //execvp("ls",myargv);
    //char *const myenv[]={
    //  "MYENV=youcanseeme",
      //NULL
    //};
    putenv("MYENV=youcanseeme");
    execle("./exec/otherproc","otherproc",NULL,environ);

    exit(1);
  }

  sleep(1);

  //father
  int status=0;
  printf("我是父进程,pid:%d\n",getpid());
  waitpid(id,&status ,0);//用来测试程序替换子进程后，子进程会不会是僵尸进程
  printf("child exit code:%d\n",WEXITSTATUS(status));



  return 0;

}
